package com.ajieee.merge.config;

import com.ajieee.merge.util.DBUtils;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.support.TransactionTemplate;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author ajieee
 * @date 2025-10-26
 */
@Configuration
public class WebConfig implements WebMvcConfigurer, ApplicationContextAware {

	@Override
	public void addCorsMappings(CorsRegistry registry) {
		registry.addMapping("/**")
				.allowedOriginPatterns("*")
				.allowedMethods("*")
				.allowedHeaders("*")
				.allowCredentials(true);
	}

	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		DBUtils.init(applicationContext.getBean(TransactionTemplate.class));
	}
}
